package com.bear.fastrepair.service

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationCompat
import com.bear.fastrepair.R

object NotificationHelper {
    const val notificationId = 13579
    fun createNotification(
        context: Context,
        content: String,
        pendingIntent: PendingIntent? = null
    ): Notification {
        val notificationManager =
            context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        val notificationChannelId = "bear_repair_fast"
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val channelName = "为保证订单正常收发，请勿关闭"
            val importance = NotificationManager.IMPORTANCE_HIGH
            val notificationChannel =
                NotificationChannel(notificationChannelId, channelName, importance)
            notificationChannel.description = "小熊快修指定"
            notificationManager.createNotificationChannel(notificationChannel)
        }
        val builder = NotificationCompat.Builder(context, notificationChannelId)
            .setSmallIcon(R.drawable.notify)
            .setContentTitle("小熊快修")
            .setContentText(content)
        pendingIntent?.let { builder.setContentIntent(it) }
        return builder.build()
    }


    fun showNotification(
        context: Context,
        content: String,
        id: Int,
        pendingIntent: PendingIntent? = null
    ) {
        val notificationManager =
            context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        val notificationChannelId = "bear_repair_fast_notify"
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val channelName = "为保证订单正常收发，请勿关闭"
            val importance = NotificationManager.IMPORTANCE_HIGH
            val notificationChannel =
                NotificationChannel(notificationChannelId, channelName, importance)
            notificationChannel.description = "小熊快修指定"
            notificationManager.createNotificationChannel(notificationChannel)
        }
        val builder = NotificationCompat.Builder(context, notificationChannelId)
            .setSmallIcon(R.drawable.notify)
            .setContentTitle("小熊快修")
            .setContentText(content)
            .setAutoCancel(true)
            .setWhen(System.currentTimeMillis())
            .setPriority(NotificationCompat.PRIORITY_MAX)
        pendingIntent?.let { builder.setContentIntent(it) }
        notificationManager.notify(id, builder.build())
    }
}